# 数据清洗与格式化
from datetime import datetime

def clean_qa_data(raw_data):
    cleaned_data = []
    for item in raw_data:
        cleaned_item = {
            'question': item['question'].replace('\n', ' ').strip(),
            'answer': item['answer'].replace('\n', ' ').strip(),
            'category': classify_question(item['question']),
            'source': item['source'],
            'timestamp': datetime.now().isoformat()
        }
        # 过滤无效数据
        if len(cleaned_item['question']) > 5 and len(cleaned_item['answer']) > 10:
            cleaned_data.append(cleaned_item)
    return cleaned_data


def classify_question(question):
    """简单的问题分类"""
    keywords = {
        'service': ['服务', '配送', '运输', '快递'],
        'price': ['价格', '费用', '多少钱', '收费'],
        'time': ['时间', '多久', '时效', '几天'],
        'tracking': ['查询', '跟踪', '物流', '单号']
    }

    for category, words in keywords.items():
        print(f"category: {category}, words: {words}")
        if any(word in question for word in words):
            return category
    return 'other'


if __name__ == '__main__':
    tag = classify_question('帮我查一下xxx单号到哪里了')
    print(f"意图识别标签: {tag}")